package com.boboPlanet.dict.controller;

import com.alibaba.fastjson.JSON;
import com.boboPlanet.comm.result.ResponseResult;
import com.boboPlanet.dict.entity.dto.GenerateSqlDTO;
import com.boboPlanet.dict.service.GenerateSqlService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Description: TODO 自定义生成SQL
 * @Author: mis_wu
 * @Date: 2023/7/23
 * @Company planet
 **/
@RequestMapping("/sql/generate")
@RestController
public class GenerateSqlController {

    @Resource
    private GenerateSqlService generateSqlService;

    @PostMapping("/insertOne")
    public ResponseResult<String> generateSqlByFiledList(@RequestBody GenerateSqlDTO sqlDTO){
        return ResponseResult.isSuccess(generateSqlService.generateSqlByFiledList(sqlDTO));
    }

    @PostMapping("/insertSQL")
    public ResponseResult<String> generateSqlByFiledList(@RequestBody MultipartFile excelFile, @RequestParam String sqlDTO){
        GenerateSqlDTO generateSqlDTO = JSON.parseObject(sqlDTO, GenerateSqlDTO.class);
        return ResponseResult.isSuccess(generateSqlService.generateSqlByFile(excelFile,generateSqlDTO));
    }
}
